package com.member.shop.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.member.common.annotation.Log;
import com.member.common.core.controller.BaseController;
import com.member.common.core.domain.AjaxResult;
import com.member.common.core.page.TableDataInfo;
import com.member.common.enums.BusinessType;
import com.member.common.enums.OrderDeleteEnum;
import com.member.common.utils.poi.ExcelUtil;
import com.member.shop.domain.SysBizGoods;
import com.member.shop.domain.SysBizMarketPage;
import com.member.shop.service.ISysBizMarketPageService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 【营销页面定义】控制器
 *
 * @author lixinchen
 * @version 1.0
 * @date 2025-02-14
 **/
@RestController
@RequestMapping("/shop/marketPage")
public class SysBizMarketPageController extends BaseController {
    @Resource
    private ISysBizMarketPageService sysBizMarketPageService;

    /**
     * 查询营销页面定义列表
     */
    @PreAuthorize("@ss.hasPermi('shop:marketPage:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysBizMarketPage sysBizMarketPage) {
        setTenantId(sysBizMarketPage);
        startPage();
        LambdaQueryWrapper<SysBizMarketPage> queryWrapper = new LambdaQueryWrapper<SysBizMarketPage>();
        queryWrapper.eq(SysBizMarketPage::getDeleted, OrderDeleteEnum.NOT_DELETE.getKey());
        queryWrapper.eq(sysBizMarketPage.getDisplayed()!=null,SysBizMarketPage::getDisplayed, sysBizMarketPage.getDisplayed());
        queryWrapper.eq(sysBizMarketPage.getTenantId()!=null,SysBizMarketPage::getTenantId, sysBizMarketPage.getTenantId());
        queryWrapper.orderByDesc(SysBizMarketPage::getId);
        List<SysBizMarketPage> list = sysBizMarketPageService.selectSysBizMarketPageList(queryWrapper);
        return getDataTable(list);
    }

    private void setTenantId(SysBizMarketPage sysBizMarketPage) {
        Long tenantId = getTenantId();
        if (tenantId != null && tenantId > 0) {
            sysBizMarketPage.setTenantId(tenantId);
        }
    }

    /**
     * 导出营销页面定义列表
     */
    @PreAuthorize("@ss.hasPermi('shop:marketPage:export')")
    @Log(title = "营销页面定义", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysBizMarketPage sysBizMarketPage) {
        LambdaQueryWrapper<SysBizMarketPage> queryWrapper = new LambdaQueryWrapper<SysBizMarketPage>();
        List<SysBizMarketPage> list = sysBizMarketPageService.selectSysBizMarketPageList(queryWrapper);
        ExcelUtil<SysBizMarketPage> util = new ExcelUtil<SysBizMarketPage>(SysBizMarketPage.class);
        util.exportExcel(response, list, "营销页面定义数据");
    }

    /**
     * 获取营销页面定义详细信息
     */
    @PreAuthorize("@ss.hasPermi('shop:marketPage:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(sysBizMarketPageService.selectSysBizMarketPageById(id));
    }

    /**
     * 新增营销页面定义
     */
    @PreAuthorize("@ss.hasPermi('shop:marketPage:add')")
    @Log(title = "营销页面定义", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysBizMarketPage sysBizMarketPage) {
        return toAjax(sysBizMarketPageService.insertSysBizMarketPage(sysBizMarketPage));
    }

    /**
     * 修改营销页面定义
     */
    @PreAuthorize("@ss.hasPermi('shop:marketPage:edit')")
    @Log(title = "营销页面定义", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysBizMarketPage sysBizMarketPage) {
        return toAjax(sysBizMarketPageService.updateSysBizMarketPage(sysBizMarketPage));
    }

    /**
     * 删除营销页面定义
     */
    @PreAuthorize("@ss.hasPermi('shop:marketPage:remove')")
    @Log(title = "营销页面定义", businessType = BusinessType.DELETE)
    @DeleteMapping("/{id}")
    public AjaxResult remove(@PathVariable Long id) {
        return toAjax(sysBizMarketPageService.deleteSysBizMarketPageById(id));
    }
}
